package com.song.hbaseChap_5_02;

import java.io.IOException;

import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapreduce.Mapper;


public class ExampleOutMapper extends Mapper<LongWritable, Text, ImmutableBytesWritable, Put>{
	
	
	private String rowkey = null;
	private byte[] family = null;
	private byte[] qualifier = null;
	private byte[] val = null;
	
	
	@Override
	protected void map(
			LongWritable key,
			Text value,
			Context context)
			throws IOException, InterruptedException {
		// TODO Auto-generated method stub
		
		String line  = value.toString();
		String[] arr = line.split("\t", -1);
		
		if(arr.length == 2)
		{
			rowkey = arr[0];
			
			String[] values= arr[1].split(":");
			if(values.length == 3)
			{
				family = values[0].getBytes();
				qualifier = values[1].getBytes();
				val = values[2].getBytes();
				Put put = new Put(rowkey.getBytes());
				put.add(family , qualifier, val);
				context.write(new ImmutableBytesWritable(rowkey.getBytes()),  put);
			}
		}
		
		
	}

	
	
	
	
}
